package com.twu.biblioteca;

import java.util.Scanner;

public abstract class Menu {
    private static final String MENU_OPTION_FORMAT = "  [%d] %s";
    protected String[] optionDescriptions;
    protected BookList availableBooks;
    protected BookList checkoutBooks;
    protected MovieList availableMovies;
    protected MovieList checkoutMovies;

    public int readInputOption() {
        System.out.print("Please Input Your Option: ");
        Scanner scanner = new Scanner(System.in);
        return scanner.nextInt();
    }

    public void printMenu() {
        printMenuHead();
        printMenuOptions();
        printMenuEnd();
    }

    public abstract Menu handleOption(int option);

    private void printMenuHead() {
        String menuHead = "###############################################################\n" +
                "                    _      _     __  \n" +
                "                   / \\    / \\   |__ |\\  |  \n" +
                "                  /   \\  /   \\  |__ | \\ | |  |  \n" +
                "                 /     \\/     \\     |  \\| |__|     \n\n" +
                "###############################################################\n";
        System.out.println(menuHead);
    }

    private void printMenuOptions() {
        for (int i = 0; i < optionDescriptions.length; i++) {
            System.out.println(String.format(MENU_OPTION_FORMAT, i+1, optionDescriptions[i]));
        }
    }

    private void printMenuEnd() {
        System.out.println("\n###############################################################\n");
    }

    protected Boolean selectAWrongOption(int option) {
        if (option < 1 || option > optionDescriptions.length) {
            System.out.println("*******************  Select a valid option!  *******************\n");
            return true;
        }
        return false;
    }
}
